package org.ztest.serialize;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class TestSerialize
{
    public void testWrite() throws IOException
    {
        TestClass tc = new TestClass();
        tc.setCls(new SubClass());
        try (FileOutputStream fos = new FileOutputStream("F:\\workspace\\Demo\\ztest\\src\\main\\resources\\data\\Data.txt"))
        {
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(tc);
            oos.close();
        }
    }
    
    public void testRead() throws IOException, ClassNotFoundException
    {
        try (FileInputStream fis = new FileInputStream("F:\\workspace\\Demo\\ztest\\src\\main\\resources\\data\\Data.txt"))
        {
            ObjectInputStream ois = new ObjectInputStream(fis);
            TestClass tc = (TestClass) ois.readObject();
            System.out.println(tc.getCls());
        }
    }
}
